package com.awspaas.user.apps.cpq.controller;

import java.util.ArrayList;
import java.util.List;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;

public class CPQ_GetInstallationFeeSystemWeb {

	public String getInstallationFeeSystem(UserContext userContext, String bindId, String xmlx, String cpxh,
			String systemBHs) {
		try {
			String[] bhs=systemBHs.split(",");
			String bhsql="";
			SDK.getBOAPI().removeByBindId("BO_EU_CQP_INSTALLATION_FEE_TEMPLATE_GRID", bindId);
			if(bhs.length>0) {
				for (String bh : bhs) {
					if(bhsql.isEmpty()) {
						bhsql="'"+bh+"'";
					}else {
						bhsql+=",'"+bh+"'";
					}
					//将安装费用也作为系统模块放入模块清单子表中。
					//bhsql+=",'AZF'";
				}
			}
			String sql="select a.MKMC,b.XTMC,b.XTMH from BO_EU_CPQ_IF_SYSTEM_GRID a "
					+ "LEFT JOIN BO_EU_CPQ_IF_SYSTEM b on a.BINDID=b.BINDID   " + 
					"where  b.XTMH in ("+bhsql+")";
			List<RowMap> maps=DBSql.getMaps(sql);
			List<BO> bos=new ArrayList<BO>();
			if(maps.size()>0) {
				for (RowMap rowMap : maps) {
					String XTMC=rowMap.getString("XTMC");
					String MKMC=rowMap.getString("MKMC");
					String XTMH=rowMap.getString("XTMH");
					BO data=new BO();
					data.set("XTMC", XTMC);//系统名称
					data.set("LX",MKMC );//模块名称
					data.set("XTMH", XTMH);	//系统编号
					bos.add(data);
				}
				SDK.getBOAPI().create("BO_EU_CQP_INSTALLATION_FEE_TEMPLATE_GRID", bos, bindId, userContext.getUID());
			}
			 ResponseObject ro = ResponseObject.newOkResponse();
			   return ro.toString();
		} catch (Exception e) {
			throw e;
		}
		
	}

}
